package com.liwalo.dao;

// Generated 24-ago-2013 14:46:30 by Hibernate Tools 3.6.0

import static org.hibernate.criterion.Example.create;

import java.util.List;

import javax.naming.InitialContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.liwalo.entities.ProveedorPotencial;
import com.liwalo.utils.HibernateUtil;

/**
 * Home object for domain model class ProveedorPotencial.
 * @see com.liwalo.dao.ProveedorPotencial
 * @author Hibernate Tools
 */
public class ProveedorPotencialDAO {

	private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

	public void persist(ProveedorPotencial transientInstance) {
		ProveedorPotencial provider = null;
		Session session = sessionFactory.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try {
			session.save(transientInstance);
			tx.commit();
		} catch (RuntimeException re) {
			tx.rollback();
			re.printStackTrace();
		}
	}

	public void update(ProveedorPotencial instance) {
		Session session = sessionFactory.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try {
			session.saveOrUpdate(instance);
			tx.commit();
		} catch (RuntimeException re) {
			tx.rollback();
			re.printStackTrace();
		}
	}

	public void attachClean(ProveedorPotencial instance) {
		Session session = sessionFactory.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try {
			session.lock(instance, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			tx.rollback();
			re.printStackTrace();
		}
	}

	public void delete(ProveedorPotencial persistentInstance) {
		Session session = sessionFactory.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try {
			session.delete(persistentInstance);
			tx.commit();
		} catch (RuntimeException re) {
			tx.rollback();
			re.printStackTrace();
		}
	}

	public ProveedorPotencial merge(ProveedorPotencial detachedInstance) {
		Session session = sessionFactory.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try {
			ProveedorPotencial result = (ProveedorPotencial) session.merge(detachedInstance);
			tx.commit();
			return result;
		} catch (RuntimeException re) {
			tx.rollback();
			re.printStackTrace();
		}
		return null;
	}

	public ProveedorPotencial findById(java.lang.Integer id) {
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		try {
			ProveedorPotencial instance = (ProveedorPotencial) session.get(ProveedorPotencial.class, id);
			return instance;
		} catch (RuntimeException re) {
			re.printStackTrace();
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<ProveedorPotencial> findByExample(ProveedorPotencial instance) {
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		List<ProveedorPotencial> results = null;
		try {
			Criteria crit = session.createCriteria(ProveedorPotencial.class).add(create(instance));
			results= (List<ProveedorPotencial>) crit.list();
		} catch (RuntimeException re) {
			re.printStackTrace();
		}
		return results;
	}
}
